package update_grammar;

import java.util.LinkedList;

/**
 * @author Zlatka Trajcheska, Marija Petkovska
 * @version 1.0 18.02.2013 
 * 
 * This class is used for seeking the rule based on its id.
 */
public class ListOfRules 
{

    LinkedList<Rule> rulesList = new LinkedList<Rule>();

    /**
	 * This method is the constructor of the class. We use it to input the rules of the grammar
	 */
    public ListOfRules()
    {
        this.rulesList=new LinkedList<Rule>();

        LinkedList<String> tmp = new LinkedList<String>();
        
        //1.  EXPRESSION : variable = ARITHMETIC ; REMAINDER 
        tmp.add("variable");
        tmp.add("=");
        tmp.add("ARITHMETIC");
        tmp.add(";");
        tmp.add("REMAINDER");
        
        this.rulesList.add(new Rule(1,tmp));
        tmp.clear();
        
        //2.	ARITHMETIC =   VARIABLE  ARITHMETIC_REMAINDER
        tmp.add("VARIABLE");
        tmp.add("ARITHMETIC_REMAINDER");
        
        this.rulesList.add(new Rule(2,tmp));
        tmp.clear();
        
        //3.	ARITHMETIC_REMAINDER = + VARIABLE   ARITHMETIC_REMAINDER
        tmp.add("+");
        tmp.add("VARIABLE");
        tmp.add("ARITHMETIC_REMAINDER");
        
        this.rulesList.add(new Rule(3,tmp));
        tmp.clear();
        
        //4.	ARITHMETIC_REMAINDER = - VARIABLE   ARITHMETIC_REMAINDER
        tmp.add("-");
        tmp.add("VARIABLE");
        tmp.add("ARITHMETIC_REMAINDER");
        
        this.rulesList.add(new Rule(4,tmp));
        tmp.clear();
        
        //5.	ARITHMETIC_REMAINDER = e
        tmp.add("e");
        
        this.rulesList.add(new Rule(5,tmp));
        tmp.clear();
  
		//6.	VARIABLE = variable
        tmp.add("variable");

        this.rulesList.add(new Rule(6,tmp));
        tmp.clear();
        
        //7.	VARIABLE = constant
        tmp.add("constant");
        
        this.rulesList.add(new Rule(7,tmp));
        tmp.clear();
        
        
        //8.	REMAINDER = EXPRESSION
        tmp.add("EXPRESSION");
        
        this.rulesList.add(new Rule(8,tmp));
        tmp.clear();
        
		//9.	REMAINDER = e
        tmp.add("e");
        
        this.rulesList.add(new Rule(9,tmp));
        tmp.clear();

      
        
    }
    
    /**
	 * This method is used to find a cerftain rule in the grammar based on its id.
	 * 
	 * @param int id - the id of the rule
	 * @return LinkedList<String> l - the list of terminals/nonterminals of the rule in the given order
	 */
    public LinkedList<String> find(int id)
    {

        for(int i=0;i<this.rulesList.size();i++)
        {
            if(this.rulesList.get(i).getRuleID()==id)
            {
                return this.rulesList.get(i).getRuleList();
            }
        }
        return null;
    }

}